<template>
  <div class="register-wrapper">
    <el-col :span="6">
      <stick class="side-stick"></stick>
    </el-col>
    <el-col :span="12" class="register-wrapper">
      <board-scroll-card>
        <div class="register-container">
          <div class="form-header">
            <h2>创建账号</h2>
            <p>开启您的美好旅程</p>
          </div>
          <form @submit.prevent="handleRegister" class="floating-form">
            <div class="input-group">
              <input type="text" id="username" v-model="username" required maxlength="20" />
              <label for="username">用户名</label>
              <span class="highlight"></span>
            </div>

            <div class="input-group">
              <input type="password" id="password" v-model="password" required minlength="6" maxlength="20" />
              <label for="password">密码</label>
              <span class="highlight"></span>
            </div>
            <div class="input-group">
              <input type="password" id="confirmPassword" v-model="confirmPassword" required minlength="6" maxlength="20" />
              <label for="confirmPassword">确认密码</label>
              <span class="highlight"></span>
            </div>
            <button type="submit" class="submit-btn">
              <span>立即注册</span>
              <i class="arrow-icon"></i>
            </button>
            <div class="form-footer">
              <span>已有账号？</span>
              <a href="/login">立即登录</a>
            </div>
          </form>
        </div>
      </board-scroll-card>
    </el-col>
    <el-col :span="6">
      <stick class="side-stick"></stick>
    </el-col>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import {ElMessage} from "element-plus";
import {register} from "@/api/user.js";
import CryptoJS from "crypto-js";
import router from "@/routers/index.js";
import BoardScrollCard from "@/components/BoardScrollCard.vue";
import Stick from "@/components/stick.vue";

const username = ref('')
const password = ref('')
const confirmPassword = ref('')

const handleRegister = async () => {
  if (password.value !== confirmPassword.value) {
    ElMessage.warning("两次输入的密码不一致");
    return;
  }
  console.log('Registering...');
  try {
    const encryptedPassword = CryptoJS.MD5(password.value).toString();
    await register({ username: username.value, password: encryptedPassword });
  } catch (error) {
    console.error('Registration failed:', error);
  }
};




</script>

<style scoped>
.register-wrapper {
  min-height: 93.5vh;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
  padding: 10px;
  box-sizing: border-box;
}

.register-wrapper > .el-col {
  display: flex;
  justify-content: center;
}

.register-container {
  width: 100vw;
  max-width: 40vw;
  background: white;
  border-radius: 16px;
  padding: 30px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
  z-index: 1;
  box-sizing: border-box;
}

.form-header {
  text-align: center;
  margin-bottom: 30px;
}

.form-header h2 {
  color: #2c3e50;
  font-size: clamp(24px, 6vw, 32px);
  margin-bottom: 8px;
  font-weight: 700;
}

.form-header p {
  color: #95a5a6;
  font-size: clamp(14px, 3.5vw, 16px);
}

.floating-form .input-group {
  position: relative;
  margin-bottom: 25px;
}

.input-group input {
  width: 100%;
  padding: 14px;
  border: 2px solid #e0e0e0;
  border-radius: 10px;
  font-size: clamp(15px, 4vw, 16px);
  transition: all 0.3s ease;
  background: transparent;
  box-sizing: border-box;
}

.input-group label {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  background: white;
  padding: 0 5px;
  color: #95a5a6;
  font-size: clamp(14px, 4vw, 16px);
  transition: all 0.3s ease;
  pointer-events: none;
}

.input-group input:focus,
.input-group input:valid {
  border-color: #3498db;
}

.input-group input:focus + label,
.input-group input:valid + label {
  top: 0;
  font-size: 13px;
  color: #3498db;
}

.verification-group {
  display: flex;
  gap: 10px;
}

.verification-group input {
  flex: 1;
}

.send-code-btn {
  padding: 0 15px;
  background: #e8f5fe;
  color: #3498db;
  border: none;
  border-radius: 10px;
  font-size: clamp(13px, 3.5vw, 14px);
  cursor: pointer;
  transition: all 0.3s ease;
  white-space: nowrap;
}

.send-code-btn:hover {
  background: #d0e9fd;
}

.submit-btn {
  width: 100%;
  padding: 14px;
  background: linear-gradient(to right, #3498db, #2980b9);
  color: white;
  border: none;
  border-radius: 10px;
  font-size: clamp(16px, 4.5vw, 18px);
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.submit-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(52, 152, 219, 0.3);
}

.arrow-icon {
  border: solid white;
  border-width: 0 2px 2px 0;
  display: inline-block;
  padding: 3px;
  transform: rotate(-45deg);
}

.form-footer {
  text-align: center;
  margin-top: 20px;
  color: #95a5a6;
  font-size: clamp(13px, 3.5vw, 14px);
}

.form-footer a {
  color: #3498db;
  text-decoration: none;
  margin-left: 5px;
  font-weight: 600;
}

.form-footer a:hover {
  text-decoration: underline;
}

/* 移动端特定样式 */
@media (max-width: 992px) {
  .register-wrapper > .el-col {
    width: 100% !important;
    max-width: 100%;
  }

  .side-stick {
    display: none;
  }
}

@media (max-width: 767px) {

  .register-container {
    max-width: 85vw;
    padding: 25px;
  }

  .verification-group {
    flex-direction: column;
    gap: 10px;
  }

  .send-code-btn {
    width: 100%;
    padding: 12px;
  }
}

@media (max-width: 480px) {
  .register-container {
    max-width: 85vw;
    padding: 20px;
    border-radius: 12px;
  }

  .input-group {
    margin-bottom: 20px;
  }

  .input-group input {
    padding: 12px;
  }

  .submit-btn {
    padding: 12px;
  }
}

/* 横屏优化 */
@media screen and (max-width: 767px) and (orientation: landscape) {
  .register-wrapper {
    min-height: auto;
    padding-top: 20px;
  }

  .register-container {
    max-width: 85vw;
    max-width: 90%;
    padding: 15px;
  }

  .form-header {
    margin-bottom: 15px;
  }

  .floating-form .input-group {
    margin-bottom: 15px;
  }
}

/* 超大字体设备优化 */
@media screen and (min-width: 768px) and (max-width: 1024px) and (orientation: portrait) {
  .form-header h2 {
    font-size: 28px;
  }

  .input-group input {
    padding: 16px;
    font-size: 18px;
  }

  .submit-btn {
    padding: 16px;
    font-size: 18px;
  }
}
</style>